package com.example.a15954.myapplication.Activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.a15954.myapplication.R;

import android_serialport_api.CommandSender;

public class YinjianActivity extends AppCompatActivity {

    private EditText et_wind;
    private EditText et_1;
    private EditText et_2;
    private EditText et_3;
    private EditText et_4;
    private EditText et_5;
    private EditText et_7;
    private Button bt_sure1;
    private Button bt_sure2;
    private EditText et_y;
    private EditText et_z;
    private Button bt_sure3;
    private Button bt_sure4;
    private EditText et_a;
    private EditText et_b;
    private Button bt_sure5;
    private Button bt_sure6;
    private EditText et_8;
    private EditText et_9;
    private EditText et_10;
    private EditText et_11;
    private EditText et_12;
    private EditText et_13;
    private EditText et_14;
    private EditText et_15;
    private EditText et_16;
    private EditText et_17;
    private EditText et_18;
    private Button bt_sure7;
    private Button bt_sure8;
    private EditText et_19;
    private EditText et_other;
    private Button bt_sure9;
    private EditText et_other1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_yinjian);
        CommandSender.init();
        initView();
        initData();
    }
    //out4 out5 out6

    private void initView() {
        //风机T2
        et_wind = (EditText) findViewById(R.id.et_wind);
        //T1
        et_1 = (EditText) findViewById(R.id.et_1);
        //T3
        et_2 = (EditText) findViewById(R.id.et_2);
        //T4
        et_3 = (EditText) findViewById(R.id.et_3);
        //T5
        et_4 = (EditText) findViewById(R.id.et_4);
        //T6
        et_5 = (EditText) findViewById(R.id.et_5);
        //T7
        et_7 = (EditText) findViewById(R.id.et_7);
        //按钮
        bt_sure1 = (Button) findViewById(R.id.bt_sure1);
        bt_sure2 = (Button) findViewById(R.id.bt_sure2);
        //舵机
        et_y = (EditText) findViewById(R.id.et_Y);
        et_z = (EditText) findViewById(R.id.et_Z);
        et_a = (EditText) findViewById(R.id.et_A);
        et_b = (EditText) findViewById(R.id.et_B);
        //按钮
        bt_sure3 = (Button) findViewById(R.id.bt_sure3);
        bt_sure4 = (Button) findViewById(R.id.bt_sure4);
        bt_sure5 = (Button) findViewById(R.id.bt_sure5);
        bt_sure6 = (Button) findViewById(R.id.bt_sure6);


        //其他的T开头数据
        et_8 = (EditText) findViewById(R.id.et_8);
        et_9 = (EditText) findViewById(R.id.et_9);
        et_10 = (EditText) findViewById(R.id.et_10);
        et_11 = (EditText) findViewById(R.id.et_11);
        et_12 = (EditText) findViewById(R.id.et_12);
        et_13 = (EditText) findViewById(R.id.et_13);
        //下一个
        et_14 = (EditText) findViewById(R.id.et_14);
        et_15 = (EditText) findViewById(R.id.et_15);
        et_16 = (EditText) findViewById(R.id.et_16);
        et_17 = (EditText) findViewById(R.id.et_17);
        et_18 = (EditText) findViewById(R.id.et_18);
        et_19 = (EditText) findViewById(R.id.et_19);
        //按钮：
        bt_sure7 = (Button) findViewById(R.id.bt_sure7);
        bt_sure8 = (Button) findViewById(R.id.bt_sure8);
        //任意命令
        et_other = (EditText) findViewById(R.id.et_other);
        et_other1 = (EditText) findViewById(R.id.et_other1);
        bt_sure9 = (Button) findViewById(R.id.bt_sure9);

    }

    private void initData() {
        //任意命令
        bt_sure9.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String s1 = et_other.getText().toString();
                String s2 = et_other1.getText().toString();
                CommandSender.send("M110 T"+s1 +" S"+s2);
                System.out.println("输入的命令是======"+"M110 T"+s1 +" S"+s2);
               // CommandSender.send(et_other.getText().toString());
                System.out.println("任意命令==="+et_other.getText().toString());
            }
        });

        bt_sure7.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                CommandSender.send("M110 T8 S" + et_8.getText().toString());
                CommandSender.send("M110 T9 S" + et_9.getText().toString());
                CommandSender.send("M110 T10 S" + et_10.getText().toString());
                CommandSender.send("M110 T11 S" + et_11.getText().toString());
                CommandSender.send("M110 T12 S" + et_12.getText().toString());
                CommandSender.send("M110 T13 S" + et_13.getText().toString());

                System.out.println("T的相关命令字符==="+"M110 T8 S" + et_8.getText().toString()+"M110 T9 S" + et_9.getText().toString()
                +"M110 T10 S" + et_10.getText().toString()+"M110 T11 S" + et_11.getText().toString()+"M110 T12 S" + et_12.getText().toString()
                        +"M110 T13 S" + et_13.getText().toString()
                );
            }
        });
        bt_sure8.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                CommandSender.send("M110 T14 S" + et_14.getText().toString());
                CommandSender.send("M110 T15 S" + et_15.getText().toString());
                CommandSender.send("M110 T16 S" + et_16.getText().toString());
                CommandSender.send("M110 T17 S" + et_17.getText().toString());
                CommandSender.send("M110 T18 S" + et_18.getText().toString());
                CommandSender.send("M110 T19 S" + et_19.getText().toString());
                System.out.println("M110 T14 S" + et_14.getText().toString()+"M110 T15 S" + et_15.getText().toString()+"M110 T16 S" + et_16.getText().toString()
                +"M110 T17 S" + et_17.getText().toString()+"M110 T18 S" + et_18.getText().toString()+"M110 T19 S" + et_19.getText().toString()
                );
            }
        });


        bt_sure5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                CommandSender.send("G1 A" + et_a.getText().toString());
            }
        });
        bt_sure6.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                CommandSender.send("G1 B" + et_b.getText().toString());
            }
        });
        bt_sure4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                CommandSender.send("G1 Z" + et_z.getText().toString());
            }
        });
        bt_sure3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                CommandSender.send("G1 Y" + et_y.getText().toString());
                //   CommandSender.send("G1 Z"+et_z.getText().toString());
            }
        });
        bt_sure1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (et_wind.getText().toString().equals("") || et_wind.getText().toString() == null) {
                    Toast.makeText(YinjianActivity.this, "输入命令不能为空", Toast.LENGTH_LONG).show();
                } else {
                    CommandSender.send("M110 T2 S" + et_wind.getText().toString());
                }

            }
        });
        bt_sure2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                CommandSender.send("M110 T1 S" + et_1.getText().toString());
                CommandSender.send("M110 T3 S" + et_2.getText().toString());
                CommandSender.send("M110 T4 S" + et_3.getText().toString());
                CommandSender.send("M110 T5 S" + et_4.getText().toString());
                CommandSender.send("M110 T6 S" + et_5.getText().toString());
                CommandSender.send("M110 T7 S" + et_7.getText().toString());
                System.out.println("M110 T1 S" + et_1.getText().toString()+"M110 T3 S" + et_2.getText().toString()+"M110 T4 S" + et_3.getText().toString()
                +"M110 T5 S" + et_4.getText().toString()+"M110 T6 S" + et_5.getText().toString()+"M110 T7 S" + et_7.getText().toString()
                );
            }
        });


    }

}
